package com.nickstumpos.android.easyVolume.streams;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.nickstumpos.android.easyVolume.R;
import com.nickstumpos.android.easyVolume.manager.ScreenManager;
import com.nickstumpos.android.easyVolume.playRinger.IPlaySample;
import com.nickstumpos.android.easyVolume.streams.controller.StreamController;
import com.nickstumpos.android.easyVolume.streams.types.Stream;
import com.nickstumpos.android.easyVolume.volume.levels.VibrateLevel;
import com.nickstumpos.android.easyVolume.volume.levels.VolumeLevel;

public abstract class AbstractVolumeScreen extends RelativeLayout implements
		IStreamScreen {

	/**
	 * @return the pLAY
	 */
	protected static int getPLAY() {
		return AbstractVolumeScreen.PLAY;
	}

	/**
	 * @return the sTOP
	 */
	protected static int getSTOP() {
		return AbstractVolumeScreen.STOP;
	}

	private ImageButton					high						= null;
	private ImageButton					medHigh					= null;
	private ImageButton					medium					= null;
	private ImageButton					medLow					= null;
	private ImageButton					low							= null;
	private ImageButton					vibrateOnly			= null;
	private ImageButton					silent					= null;
	private ImageButton					playMedia				= null;
	private ImageButton					vibeButton			= null;
	private ScreenManager				manager					= null;
	private boolean							playDisabled		= false;
	private CheckBox						checkbox;
	private StreamController		streamController;

	private TextView						volumeStatus;

	private boolean							vibrateSwitch		= false;

	private boolean							vibeState				= false;
	private Stream							stream;

	private boolean							slave						= false;

	private int									unpressedId			= R.drawable.button_unpressed;

	private int									pressedId				= R.drawable.button_pressed;

	private int									vibe_on_draw		= R.drawable.vibe_on;

	private int									vibe_off_draw		= R.drawable.vibe_off;

	private boolean							isVibeDisabled	= false;

	private boolean							inactive				= false;

	private boolean							playing					= false;

	protected static final int	PLAY						= 0;
	protected static final int	STOP						= 1;
	private VolumeLevel					lastSetVolume;
	private IPlaySample					playSample;

	public AbstractVolumeScreen(Context context) {
		super(context);
		this.streamController = new StreamController(context);
	}

	public AbstractVolumeScreen(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.streamController = new StreamController(context);
	}

	public AbstractVolumeScreen(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.streamController = new StreamController(context);
	}

	public void cleanup() {
		this.manager = null;

		if (this.playSample != null) {
			this.playSample.stop();
		}
		this.playSample = null;
	}

	public void DecreaseVolumeLevel() {
		if (!this.inactive) {
			switch (this.getLastSetVolume()) {
				case HIGH:
					this.setStreamVolumeLevel(VolumeLevel.MED_HIGH);
					break;
				case MED_HIGH:
					this.setStreamVolumeLevel(VolumeLevel.MEDIUM);
					break;
				case MEDIUM:
					this.setStreamVolumeLevel(VolumeLevel.MED_LOW);
					break;
				case MED_LOW:
					this.setStreamVolumeLevel(VolumeLevel.LOW);
					break;
				case LOW:
					if (this.vibrateOnly != null) {
						this.setStreamVolumeLevel(VolumeLevel.VIBE_ONLY);
					} else {
						this.setStreamVolumeLevel(VolumeLevel.SILENT);
					}
					break;
				case VIBE_ONLY:
					this.setStreamVolumeLevel(VolumeLevel.SILENT);
					break;
				case SILENT:
					break;
			}
		}
	}

	protected void disableButtons() {
		this.unpressedId = R.drawable.button_unpressed_disabled;
		this.pressedId = R.drawable.button_pressed_disabled;
		this.setInactive(true);
	}

	protected void disableVibeButton() {
		if (this.vibeButton != null) {
			this.isVibeDisabled = true;
			this.vibe_on_draw = R.drawable.vibe_on_disabled;
			this.vibe_off_draw = R.drawable.vibe_off_disabled;
			this.redrawVibeButton();
		}
	}

	protected void enableButtons() {
		this.unpressedId = R.drawable.button_unpressed;
		this.pressedId = R.drawable.button_pressed;
		this.setInactive(false);
	}

	protected void enableVibeButton() {
		this.vibe_on_draw = R.drawable.vibe_on;
		this.vibe_off_draw = R.drawable.vibe_off;
		this.setVibrate(this.vibrateSwitch ? VibrateLevel.VIBE_ON
				: VibrateLevel.VIBE_OFF);
		this.isVibeDisabled = false;
	}

	/**
	 * @return the checkbox
	 */
	protected CheckBox getCheckbox() {
		return this.checkbox;
	}

	/**
	 * @return the high
	 */
	protected ImageButton getHigh() {
		return this.high;
	}

	/**
	 * @return the lastSetVolume
	 */
	protected VolumeLevel getLastSetVolume() {
		return this.lastSetVolume;
	}

	/**
	 * @return the low
	 */
	protected ImageButton getLow() {

		return this.low;
	}

	protected ScreenManager getManager() {
		return this.manager;
	}

	/**
	 * @return the medHigh
	 */
	protected ImageButton getMedHigh() {
		return this.medHigh;
	}

	/**
	 * @return the medium
	 */
	protected ImageButton getMedium() {
		return this.medium;
	}

	/**
	 * @return the medLow
	 */
	protected ImageButton getMedLow() {
		return this.medLow;
	}

	/**
	 * @return the playMedia
	 */
	protected ImageButton getPlayMedia() {
		return this.playMedia;
	}

	@Override
	public IPlaySample getPlaySample() {
		return this.playSample;
	}

	/**
	 * @return the silent
	 */
	protected ImageButton getSilent() {
		return this.silent;
	}

	/**
	 * @return the stream
	 */
	public Stream getStream() {
		return this.stream;
	}

	/**
	 * @return the streamController
	 */
	protected StreamController getStreamController() {
		return this.streamController;
	}

	/**
	 * @return the unpressedId
	 */
	protected int getUnpressedId() {
		return this.unpressedId;
	}

	/**
	 * @return the vibe_off_draw
	 */
	protected int getVibe_off_draw() {
		return this.vibe_off_draw;
	}

	/**
	 * @return the vibe_on_draw
	 */
	protected int getVibe_on_draw() {
		return this.vibe_on_draw;
	}

	/**
	 * @return the vibeButton
	 */
	protected ImageButton getVibeButton() {
		return this.vibeButton;
	}

	/**
	 * @return the vibrateOnly
	 */
	protected ImageButton getVibrateOnly() {
		return this.vibrateOnly;
	}

	/**
	 * @return the volumeStatus
	 */
	protected TextView getVolumeStatus() {
		return this.volumeStatus;
	}

	public void IncreaseVolumeLevel() {
		if (!this.inactive) {
			switch (this.getLastSetVolume()) {
				case HIGH:
					break;
				case MED_HIGH:
					this.setStreamVolumeLevel(VolumeLevel.HIGH);
					break;
				case MEDIUM:
					this.setStreamVolumeLevel(VolumeLevel.MED_HIGH);
					break;
				case MED_LOW:
					this.setStreamVolumeLevel(VolumeLevel.MEDIUM);
					break;
				case LOW:
					this.setStreamVolumeLevel(VolumeLevel.MED_LOW);
					break;
				case VIBE_ONLY:
					this.setStreamVolumeLevel(VolumeLevel.LOW);
					break;
				case SILENT:
					if (this.vibrateOnly != null) {
						this.setStreamVolumeLevel(VolumeLevel.VIBE_ONLY);
					} else {
						this.setStreamVolumeLevel(VolumeLevel.LOW);
					}
					break;
			}
		}
	}

	protected boolean isInactive() {
		return this.inactive;
	}

	/**
	 * @return the playing
	 */
	protected boolean isPlaying() {
		return this.playing;
	}

	public boolean isSlave() {
		return this.slave;
	}

	/**
	 * @return the isVibeDisabled
	 */
	protected boolean isVibeDisabled() {
		return this.isVibeDisabled;
	}

	/**
	 * @return the vibeState
	 */
	protected boolean isVibeState() {
		return this.vibeState;
	}

	/**
	 * @return the vibrateSwitch
	 */
	protected boolean isVibrateSwitch() {
		return this.vibrateSwitch;
	}

	@Override
	protected void onAnimationEnd() {
		this.onWindowVisibilityChanged(this.getVisibility());
	}

	@Override
	protected void onWindowVisibilityChanged(int visibility) {
		if (this.isPlaying() && visibility == View.GONE) {
			this.playMedia.performClick();

		}
	}

	protected void redrawVibeButton() {
		if (this.vibeState) {
			this.vibeButton.setImageResource(this.vibe_on_draw);
		} else {
			this.vibeButton.setImageResource(this.vibe_off_draw);
		}
	}

	public void refresh() {
		this.setInitialLevel();
	}

	public void setAsSlave() {
		if (this.checkbox != null) {
			this.checkbox.setChecked(true);
		}
	}

	protected void setButtonLevel(VolumeLevel level) {
		switch (level) {
			case HIGH:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("Volume: High");
				}
				if (this.high != null) {
					this.high.setImageResource(this.pressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.pressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.pressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.pressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.pressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.pressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case MED_HIGH:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("Volume: Med High");
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.pressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.pressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.pressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.pressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.pressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case MEDIUM:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("Volume: Medium");
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.unpressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.pressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.pressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.pressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.pressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case MED_LOW:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("Volume: Med Low");
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.unpressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.unpressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.pressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.pressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.pressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case LOW:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("Volume: Low");
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.unpressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.unpressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.unpressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.pressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.pressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case VIBE_ONLY:
				if (this.volumeStatus != null) {
					if (this.vibrateOnly == null) {
						this.volumeStatus.setText("Volume: Silent");
					} else {
						this.volumeStatus.setText("Volume: Vibe Only");
					}
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.unpressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.unpressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.unpressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.unpressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.pressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case SILENT:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("Volume: Silent");
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.unpressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.unpressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.unpressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.unpressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.unpressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.pressedId);
				}
				if (this.playMedia != null && this.playDisabled) {
					this.playMedia.setImageResource(R.drawable.button_start);
					this.playDisabled = false;
				}
				break;
			case NONE:
				if (this.volumeStatus != null) {
					this.volumeStatus.setText("No Slaves");
				}
				if (this.high != null) {
					this.high.setImageResource(this.unpressedId);
				}
				if (this.medHigh != null) {
					this.medHigh.setImageResource(this.unpressedId);
				}
				if (this.medium != null) {
					this.medium.setImageResource(this.unpressedId);
				}
				if (this.medLow != null) {
					this.medLow.setImageResource(this.unpressedId);
				}
				if (this.low != null) {
					this.low.setImageResource(this.unpressedId);
				}
				if (this.vibrateOnly != null) {
					this.vibrateOnly.setImageResource(this.unpressedId);
				}
				if (this.silent != null) {
					this.silent.setImageResource(this.unpressedId);
				}
				if (this.playMedia != null) {
					this.playMedia.setImageResource(R.drawable.button_start_disabled);
					this.playDisabled = true;
				}
				break;
		}

	}

	/**
	 * @param checkbox
	 *          the checkbox to set
	 */
	protected void setCheckbox(CheckBox checkbox) {
		this.checkbox = checkbox;
	}

	/**
	 * @param high
	 *          the high to set
	 */
	protected void setHigh(ImageButton high) {
		this.high = high;
	}

	protected void setInactive(boolean inactive) {
		this.inactive = inactive;
	}

	public void setInitialLevel() {
		this.vibrateSwitch = this.streamController.isVibeOn(this.stream);
		if (this.checkbox.isChecked()) {
			this.disableButtons();
			this.disableVibeButton();
		} else {
			this.enableButtons();
			if (!VolumeLevel.VIBE_ONLY.equals(this.lastSetVolume)) {
				this.enableVibeButton();
			}
		}
		this.setStreamVolumeLevel(this.streamController
				.getCurrentVolumeLevel(this.stream));
	}

	/**
	 * @param low
	 *          the low to set
	 */
	protected void setLow(ImageButton low) {
		this.low = low;
	}

	public void setManager(ScreenManager manager) {
		this.manager = manager;
	}

	/**
	 * @param medHigh
	 *          the medHigh to set
	 */
	protected void setMedHigh(ImageButton medHigh) {
		this.medHigh = medHigh;
	}

	/**
	 * @param medium
	 *          the medium to set
	 */
	protected void setMedium(ImageButton medium) {
		this.medium = medium;
	}

	/**
	 * @param medLow
	 *          the medLow to set
	 */
	protected void setMedLow(ImageButton medLow) {
		this.medLow = medLow;
	}

	public void setNotSlave() {
		if (this.slave) {
			if (this.checkbox != null) {
				this.checkbox.setChecked(false);
			}
		}
	}

	/**
	 * @param playing
	 *          the playing to set
	 */
	protected void setPlaying(boolean playing) {
		this.playing = playing;
	}

	/**
	 * @param playMedia
	 *          the playMedia to set
	 */
	protected void setPlayMedia(ImageButton playMedia) {
		this.playMedia = playMedia;
	}

	protected void setPlaySample(IPlaySample playSample) {
		this.playSample = playSample;

	}

	/**
	 * @param silent
	 *          the silent to set
	 */
	protected void setSilent(ImageButton silent) {
		this.silent = silent;
	}

	/**
	 * @param stream
	 *          the stream to set
	 */
	protected void setStream(Stream stream) {
		this.stream = stream;
	}

	/**
	 * @param streamController
	 *          the streamController to set
	 */
	protected void setStreamController(StreamController streamController) {
		this.streamController = streamController;
	}

	@Override
	public void setStreamVolumeLevel(VolumeLevel level) {
		this.lastSetVolume = level;
		if (this.stream != null) {
			this.streamController.setStreamVolumeLevel(level, this.stream);
			if (this.vibrateOnly != null) {
				if (VolumeLevel.VIBE_ONLY.equals(level)) {
					this.setVibrate(VibrateLevel.VIBE_ON);
					this.disableVibeButton();
				} else if (VolumeLevel.SILENT.equals(level)) {
					this.setVibrate(VibrateLevel.VIBE_OFF);
					this.disableVibeButton();
				} else{ 
					if(this.slave){
						this.disableVibeButton();
					}else{
						this.enableVibeButton();
					}
					if (!this.streamController.isVibeOn(this.stream)) {
						this.setVibrate(VibrateLevel.VIBE_OFF);
					} else if (this.streamController.isVibeOn(this.stream)) {
						this.setVibrate(VibrateLevel.VIBE_ON);
					}
			}
			}
		}
		this.setButtonLevel(level);
	}

	protected void setTouchListeners() {
		if (this.vibeButton != null) {
			this.vibeButton.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (!AbstractVolumeScreen.this.isVibeDisabled) {
						if (AbstractVolumeScreen.this.vibrateSwitch) {
							AbstractVolumeScreen.this.setVibrate(VibrateLevel.VIBE_OFF);
							AbstractVolumeScreen.this.vibrateSwitch = false;
							AbstractVolumeScreen.this.vibeState = false;
						} else {
							AbstractVolumeScreen.this.setVibrate(VibrateLevel.VIBE_ON);
							AbstractVolumeScreen.this.vibrateSwitch = true;
							AbstractVolumeScreen.this.vibeButton
									.setImageResource(R.drawable.vibe_on);
							AbstractVolumeScreen.this.vibeState = true;

						}
					}

				}
			});
		}
		if (this.checkbox != null) {
			this.checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					AbstractVolumeScreen.this.slave = isChecked;
					AbstractVolumeScreen.this.refresh();
					AbstractVolumeScreen.this.manager.setSlaveStatus(
							AbstractVolumeScreen.this, isChecked);
					AbstractVolumeScreen.this.manager.onSlaveChange();
				}
			});
		}
		if (this.playMedia != null) {
			this.playMedia.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					if (AbstractVolumeScreen.this.playing) {
						AbstractVolumeScreen.this.playing = false;
						AbstractVolumeScreen.this.playSample.stop();
						AbstractVolumeScreen.this.playMedia
								.setImageResource(R.drawable.button_start);
					} else {
						AbstractVolumeScreen.this.playing = true;
						AbstractVolumeScreen.this.playSample.start();
						AbstractVolumeScreen.this.playMedia
								.setImageResource(R.drawable.button_stop);
					}
				}
			});
		}
		if (this.high != null) {
			this.high.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this.setStreamVolumeLevel(VolumeLevel.HIGH);

						}
					}
					return false;
				}
			});
		}
		if (this.medHigh != null) {
			this.medHigh.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this
									.setStreamVolumeLevel(VolumeLevel.MED_HIGH);

						}
					}
					return false;
				}
			});
		}
		if (this.medium != null) {
			this.medium.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this
									.setStreamVolumeLevel(VolumeLevel.MEDIUM);

						}
					}
					return false;
				}
			});
		}
		if (this.medLow != null) {
			this.medLow.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this
									.setStreamVolumeLevel(VolumeLevel.MED_LOW);

						}
					}
					return false;
				}
			});
		}
		if (this.low != null) {
			this.low.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this.setStreamVolumeLevel(VolumeLevel.LOW);

						}
					}
					return false;
				}
			});
		}
		if (this.vibrateOnly != null) {
			this.vibrateOnly.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this
									.setStreamVolumeLevel(VolumeLevel.VIBE_ONLY);

						}
					}
					return false;
				}
			});
		}
		if (this.silent != null) {
			this.silent.setOnTouchListener(new View.OnTouchListener() {

				@Override
				public boolean onTouch(final View v, final MotionEvent event) {
					if (!AbstractVolumeScreen.this.isInactive()) {
						if (MotionEvent.ACTION_DOWN == event.getAction()) {
							AbstractVolumeScreen.this
									.setStreamVolumeLevel(VolumeLevel.SILENT);
						}
					}
					return false;
				}
			});
		}
	}

	/**
	 * @param unpressedId
	 *          the unpressedId to set
	 */
	protected void setUnpressedId(int unpressedId) {
		this.unpressedId = unpressedId;
	}

	/**
	 * @param vibe_off_draw
	 *          the vibe_off_draw to set
	 */
	protected void setVibe_off_draw(int vibe_off_draw) {
		this.vibe_off_draw = vibe_off_draw;
	}

	/**
	 * @param vibe_on_draw
	 *          the vibe_on_draw to set
	 */
	protected void setVibe_on_draw(int vibe_on_draw) {
		this.vibe_on_draw = vibe_on_draw;
	}

	/**
	 * @param vibeButton
	 *          the vibeButton to set
	 */
	protected void setVibeButton(ImageButton vibeButton) {
		this.vibeButton = vibeButton;
	}

	/**
	 * @param isVibeDisabled
	 *          the isVibeDisabled to set
	 */
	protected void setVibeDisabled(boolean isVibeDisabled) {
		this.isVibeDisabled = isVibeDisabled;
	}

	/**
	 * @param vibeState
	 *          the vibeState to set
	 */
	protected void setVibeState(boolean vibeState) {
		this.vibeState = vibeState;
	}

	protected void setVibrate(VibrateLevel level) {
		this.streamController.setVibrate(level, this.stream);
		this.vibeState = VibrateLevel.VIBE_ON.equals(level) ? true : false;
		int resource = VibrateLevel.VIBE_ON.equals(level) ? this.vibe_on_draw
				: this.vibe_off_draw;
		if (this.vibeButton != null) {
			this.vibeButton.setImageResource(resource);
		}
		if (this.stream == null) {
			this.manager.setSlaveVibrate(level);
		}
	}

	/**
	 * @param vibrateOnly
	 *          the vibrateOnly to set
	 */
	protected void setVibrateOnly(ImageButton vibrateOnly) {
		this.vibrateOnly = vibrateOnly;
	}

	/**
	 * @param vibrateSwitch
	 *          the vibrateSwitch to set
	 */
	protected void setVibrateSwitch(boolean vibrateSwitch) {
		this.vibrateSwitch = vibrateSwitch;
	}

	/**
	 * @param volumeStatus
	 *          the volumeStatus to set
	 */
	protected void setVolumeStatus(TextView volumeStatus) {
		this.volumeStatus = volumeStatus;
	}

	public void vibrateSwitch(VibrateLevel level) {
		this.setVibrate(level);
	}

}
